package cn.wolfcode.shop.web.mq;
import cn.wolfcode.shop.mq.MQDestination;
import cn.wolfcode.shop.mq.OrderMessage;
import org.apache.activemq.command.ActiveMQObjectMessage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jms.core.JmsTemplate;
import org.springframework.stereotype.Component;

import javax.jms.JMSException;
import javax.jms.ObjectMessage;
@Component
public class MQSender {
    @Autowired
    private JmsTemplate jmsTemplate;
    public void sendOrderMessage(OrderMessage orderMessage){
        ObjectMessage objectMessage = new ActiveMQObjectMessage();
        try {
            objectMessage.setObject(orderMessage);
            jmsTemplate.convertAndSend(MQDestination.ORDER_DESTINATION,objectMessage);

        } catch (JMSException e) {
            e.printStackTrace();
        }
    }
}
